package com.service;

import com.bean.User;
import com.dao.UserDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author hecn
 * @version 1.0
 * @date 2020/8/2 0002 0:12
 * @company
 */
public class RegisterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");

        String name = req.getParameter("name");
        String password = req.getParameter("password");
        String id = req.getParameter("id");
        String sex = req.getParameter("sex");
        String telephone = req.getParameter("telephone");
        String email = req.getParameter("email");

        User user = new User(name, password, id, sex, telephone, email);
        user.toString();
        UserDao userDao = new UserDao();
        userDao.addUser(user);


        req.getRequestDispatcher("login.jsp").forward(req, resp);
    }
}
